<!-- 个人信息 -->
<template>
    <div>
        <div>
            <a-card title="微信支付参数" :bordered="false" style="width: 700px">
                <a-form :form="form" :label-col="{ span: 6 }" :wrapper-col="{ span: 17 }">
                    <a-form-item label="支付类型">
                        <a-input v-model="payType" placeholder="" ></a-input>
                    </a-form-item>
                    <a-form-item label="微信APPID">
                        <a-input v-model="appId" placeholder="" ></a-input>
                    </a-form-item>
                    <a-form-item label="商户ID">
                        <a-input v-model="mchId" placeholder="" ></a-input>
                    </a-form-item>
                    <a-form-item label="应用密钥">
                        <a-input v-model="appSecret" placeholder="" ></a-input>
                    </a-form-item>
                    <a-form-item label="序列号">
                        <a-input v-model="serial" placeholder="" ></a-input>
                    </a-form-item>
                    <a-form-item label="私钥">
                        <a-input v-model="privateKey" :rows="6" type="textarea" placeholder="" ></a-input>
                    </a-form-item>
                    <a-form-item label="公司名称">
                        <a-input v-model="description" placeholder="" ></a-input>
                    </a-form-item>
                    <a-form-item  v-bind="formItemLayoutWithOutLabel">
                        <a-button type="primary" @click="updateWeChat">确定修改</a-button>
                    </a-form-item>
                </a-form>
            </a-card>
        </div>

    </div>
</template>

<script>
import { queryWebWechatAppId , updateWebWechatAppId } from '@/api/brand';
export default {
    data () {
        return {
            brandId: this.global.brandId,
            formItemLayoutWithOutLabel: {
                wrapperCol: {
                    xs: { span: 24, offset: 0 },
                    sm: { span: 20, offset: 6 },
                },
            },
            payType: '', // 支付类型 jsapi
            appId: '', // 微信appId
            mchId: '', // 商户ID
            appSecret: '', // 应用密钥
            serial: '', // 序列号
            privateKey: '', // 私钥
            description: '', // 公司名称
            id: '',
        };
    },
    beforeCreate() {
        this.form = this.$form.createForm(this, { name: 'dynamic_rule' });
    },
    created(){
        this.queryAppId();
    },
    methods: {
        // 查询微信支付配置信息
        queryAppId(){
            let _this = this;
            const params = {
                'brandId': _this.brandId,
            }
            queryWebWechatAppId(params)
            .then(res=>{
                if(res.success){
                    if(res.data.id){
                        var item = res.data
                        _this.payType = item.payType
                        _this.mchId = item.mchId
                        _this.appId = item.appId
                        _this.appSecret = item.appSecret
                        _this.serial = item.serial
                        _this.privateKey = item.privateKey
                        _this.description = item.description
                        _this.id = item.id
                    }
                }else{
                    _this.$notification['error']({
                        message: '提示',
                        description: res.errMessage,
                        duration: 8
                    })
                }
            })
        },
        // 添加、修改
        updateWeChat(){
            let _this = this
            const params = {
                'brandId': _this.brandId,
                'payType': _this.payType,
                'appId': _this.appId,
                'mchId': _this.mchId,
                'appSecret': _this.appSecret,
                'serial': _this.serial,
                'privateKey': _this.privateKey,
                'description': _this.description,
                'id': _this.id,
            }
            updateWebWechatAppId(params)
            .then(res=>{
                if(res.success){
                    _this.$notification['success']({
                        message: '提示',
                        description: '设置成功',
                        duration: 8
                    })
                    _this.queryAppId();
                }else{
                    _this.$notification['error']({
                        message: '提示',
                        description: res.errMessage,
                        duration: 8
                    })
                }
            })
        },
    }
}

</script>
<style scoped>

</style>